package com.kgo.eidtor.controller;

import com.google.gson.Gson;
import com.kgo.eidtor.entity.InterfaceBean;
import com.kgo.eidtor.entity.ModuleBean;
import com.kgo.eidtor.service.InterfaceService;
import com.kgo.eidtor.websocket.WebSocketServer;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author keepgoon
 * @Description: TODO
 * @date 2019/1/3114:04
 */
@RestController
@CrossOrigin
public class InterfaceController {
    @Resource
    private InterfaceService interfaceService;

    private Gson _gs = new Gson();

    /**
     * 新增接口
     * @param interfaceBean
     * @return
     */
    @RequestMapping(value = "/interface" ,method = RequestMethod.POST,produces="text/plain;charset=UTF-8")
    public String addInterface(InterfaceBean interfaceBean){
        System.out.println("接口 ： "+_gs.toJson(interfaceBean));
        return interfaceService.addInterface(interfaceBean);
    }

    /**
     * 获取接口
     * @param interfaceBean
     * @return
     */
    @RequestMapping(value = "/interfaces" ,method = RequestMethod.GET,produces="text/plain;charset=UTF-8")
    public String getInterfaces(InterfaceBean interfaceBean){
        return interfaceService.getInterfaces(interfaceBean);
    }
    @RequestMapping(value = "/interface/id" ,method = RequestMethod.GET,produces="text/plain;charset=UTF-8")
    public String getInterfaceById(String id){
        return interfaceService.getInterfaceById(id);
    }

    @RequestMapping(value = "/update/interface" ,method = RequestMethod.POST,produces="text/plain;charset=UTF-8")
    public String updateInterface(InterfaceBean interfaceBean){
        return interfaceService.updateInterfaceById(interfaceBean);
    }
}
